package com.broada.apm.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import com.broada.apm.model.performance.BasePerformance;

public class PerformanceView extends BasePerformance {
	/**
	 * @Fields serialVersionUID :
	 */

	private static final long serialVersionUID = 1L;
	private final static String uri = "uri";

	private final static String errorMessage = "errorMessage";

	private final static String name = "name";

	private final static String IP_PORT = "ip_port";
	
	private final static String src_ip = "srcIp";
	
	private List<NameAndValue> fields = new ArrayList<PerformanceView.NameAndValue>();
	
	public PerformanceView(Map<String, Object> map) {
		putAll(map);
	}

	public PerformanceView() {
		super();
	}

	@Override
	public void perfupdate() {

	}

	public PerformanceView copy() {
		return (PerformanceView) super.copy();
	}

	public void addLong(PerformanceView perf, String filedId) {
		put(filedId, getLong(filedId) + perf.getLong(filedId));
	}

	public void addDouble(PerformanceView perf, String filedId) {
		put(filedId, getDouble(filedId) + perf.getDouble(filedId));
	}

	public String getName() {
		return (String) this.get(name);
	}

	public void setName(String value) {
		this.put(name, value);
	}

	public String getUri() {
		return (String) this.get(uri);
	}

	public void setUri(String value) {
		this.put(uri, value);
	}

	public String getErrorMessage() {
		return (String) this.get(errorMessage);
	}

	public void setErrorMessage(String value) {
		this.put(errorMessage, value);
	}
	
	public String getIpPort() {
		return (String) this.get(IP_PORT);
	}

	public void setIpPort(String value) {
		this.put(IP_PORT, value);
	}

	public String getSrcIp() {
		return (String) this.get(src_ip);
	}
	
	public void setSrcIp(String value) {
		this.put(src_ip, value);
	}
	
	public List<NameAndValue> getFields() {
		return fields;
	}

	public void setFields(TreeMap<String, Object> data) {
		for (Entry<String,Object> entry : data.entrySet()) {
			this.fields.add(new NameAndValue(entry.getKey(), entry.getValue()));
		}
		this.put("fields", this.fields);
	}

	public static class NameAndValue {
		private String name;
		private Object value;

		public NameAndValue(String name, Object value) {
			super();
			this.name = name;
			this.value = value;
		}

		public NameAndValue() {
			super();
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public Object getValue() {
			return value;
		}

		public void setValue(Object value) {
			this.value = value;
		}

	}

	public void setAlertPerfBasic() {
		this.put("10Count", "0");
		this.put("20Count", "0");
		this.put("50Count", "0");
		this.put("apdexCount", "0");
		this.put("errorCount", "0");
		this.put("rpmCount", "0");
		this.put("rttCount", "0");
		this.put("successCount", "0");
		this.put("bapdexCount", "0");
		this.put("berrorCount", "0");
		this.put("brpmCount", "0");
		this.put("brttCount", "0");
		this.put("bsuccessCount", "0");
	}
}
